#! /usr/bin/env python3.3
# -*- coding: utf-8 -*-

import os
import argparse

parser = argparse.ArgumentParser(description="Create files with random data by specific size and count")
parser.add_argument("size", type=int, help="size of each file")
parser.add_argument("-c", "--count", default=1, type=int, help="count of files")
parser.add_argument("-p", "--path", default=os.getcwd(), help="parent path of files")
parser.add_argument("-u", "--unit", choices=['B', 'KB', 'MB', 'GB'], default='B', help="unit of size")
parser.add_argument("-n", "--name", default='random', help="prefix of name")
args = parser.parse_args()

nameStr = '%s_%d%s_%04d'

size = args.size
if args.unit == 'B' :
    size = args.size
elif args.unit == 'KB':
    size = args.size * 1024
elif args.unit == 'MB':
    size = args.size * 1024 * 1024
elif args.unit == 'GB':
    size = args.size * 1024 * 1024 * 1024

for i in range(args.count):
    tmpName = nameStr % (args.name, args.size, args.unit, i)
    tmpFile = os.path.join(args.path, tmpName)
    with open(tmpFile, 'wb') as fout:
        fout.write(bytearray(os.urandom(size)))
        print('%s OK' % (tmpFile))
